<?php
// 获取单个商品信息（更改信息）
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");

$gid = $_GET["gid"];

$sql = "SELECT * FROM tb_goods_info WHERE g_id = '".$gid."'";
$res = mysqli_query($conn,$sql);
if($res){
    if(mysqli_num_rows($res) <= 0){
        echo "未查询到商品信息";
        exit();
    }else{
        $row = mysqli_fetch_assoc($res);
    }
}else{
    echo "查询失败";
    exit();
}

if($row["g_is_sell"] != 1){
    echo"商品已下架，不可更改信息";
}else{
    echo"
    <form action='php/change-goods.php' method='post'>
        <div class='oldimg'><img src='../goods_imgs/".$row["g_img"]."'></div>
        <input type='hidden' name='gid' value='".$row["g_id"]."'>
        <div class='col-8'>
            <label for='goods_name' class='form-label'>商品名称</label>
            <input type='text' class='form-control' name='goods_name' id='goods_name' value='".$row['g_name']."' placeholder='输入商品名称' required>
        </div>
        <div class='col-4'>
            <label for='goods_num' class='form-label'>商品库存</label>
            <input type='number' class='form-control' name='goods_num' id='goods_num' value='".$row['g_num']."' placeholder='输入商品库存' required>
        </div>
        <div class='col-4'>
            <label for='goods_specs' class='form-label'>商品规格(Kg)</label>
            <input type='number' class='form-control' name='goods_specs' id='goods_specs' value='".$row['g_specs']."' placeholder='输入商品规格(Kg)' required>
        </div>
        <div class='col-4'>
            <label for='goods_price' class='form-label'>商品单价(元)</label>
            <input type='text' class='form-control' name='goods_price' id='goods_price' value='".$row['g_price']."' placeholder='输入商品单价(元)' required>
        </div>
        <div class='col-12'>
            <label for='goods_describe' class='form-label'>商品描述</label>
            <textarea type='text' class='form-control describe' name='goods_describe' id='goods_describe'
                placeholder='输入商品描述' required>".$row['g_describe']."</textarea>
        </div>
        <div class='col-12 btndiv'>
            <button type='submit' class='btn btn-primary'>提交</button>
        </div>
    </form>";
}